package com.youxin.logprocess.common;

import java.util.Calendar;

import com.youxin.foundation.utils.DateUtil;
/**
 * 时间工具类
 * @author yingde.cao
 *
 */
public class MonitorDateUtils {

	/**
	 * 获取当前时间分钟 YYYYMMDDMMHH
	 * 
	 * @param calendar
	 * @return String
	 */
	public static String getCurrentMinute(Calendar calendar) {
		return DateUtil.getFormatTime(calendar);
	}
	
	/**
	 * 获取时间段内
	 * @param calendar
	 * @param minuteFlag
	 * @return 
	 */
	public static String getMinuteFormatPrevious(Calendar calendar, int minuteFlag) {
		calendar=getCalendarSegment(calendar, minuteFlag);
		DateUtil.calendarMinute(calendar, -minuteFlag);
		return DateUtil.getFormatTime(calendar);
	}
	
	/**
	 * 获取当前时间段内
	 * @param calendar 日期
	 * @param minuteFlag 时间段标志
	 * @return
	 */
	public static Calendar getCalendarSegment(Calendar calendar, int minuteFlag) {
		int minute = calendar.get(Calendar.MINUTE);
		int num = minute / minuteFlag;
		int tMinute = num * minuteFlag;
		calendar.set(Calendar.MINUTE, tMinute);
		calendar.set(Calendar.SECOND, 0);
		calendar.set(Calendar.MILLISECOND, 0);
		return calendar;
	}

	/**
	 * 获取当前段内时间,假设设置10,2:45,则显示2:40.
	 * 
	 * @param calendar
	 *            日历
	 * @param minuteFlag
	 *            10分钟,15分钟,20分钟,30分钟,60分钟
	 * @return String
	 */
	public static String getMinuteFormat(Calendar calendar, int minuteFlag) {
		calendar=getCalendarSegment(calendar, minuteFlag);
		return DateUtil.getFormatTime(calendar);
	}

	/**
	 * 获取当前20分钟内的格式
	 * 
	 * @param calendar
	 * @return
	 */
	public static String getMinuteTwentyFormat(Calendar calendar) {
		return getMinuteFormat(calendar, 20);
	}
}
